package com.hongxun.design.ui.dialogstyle;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.text.InputType;
import android.text.TextUtils;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.CircleOptions;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.model.LatLng;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.zxing.WriterException;
import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.activitys.BaseActivity;
import com.hongxun.design.activitys.CreateProjectAttributeCodeActivity;
import com.hongxun.design.activitys.RegeditActivity;
import com.hongxun.design.activitys.SetPointInformationActivity;
import com.hongxun.design.adapters.BuyMenuListAdapter;
import com.hongxun.design.adapters.DialogPayAdapter;
import com.hongxun.design.adapters.PPassDialogAdapter;
import com.hongxun.design.adapters.RadioInterfaceAdapter;
import com.hongxun.design.adapters.SetPointInformationAdapter;
import com.hongxun.design.bean.BuyMenuBean;
import com.hongxun.design.bean.CodeSetBean;
import com.hongxun.design.bean.ConsumerInfo;
import com.hongxun.design.bean.CreateDistanceBean;
import com.hongxun.design.bean.Exploration;
import com.hongxun.design.bean.MaterialBean;
import com.hongxun.design.bean.NextDoorBean;
import com.hongxun.design.bean.PhotoPassagewayItemBean;
import com.hongxun.design.bean.ProjectItemBean;
import com.hongxun.design.bean.ScanHotBean;
import com.hongxun.design.bean.SetPointInfItemBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.jungong.activity.ProItemInfoActivity;
import com.hongxun.design.jungong.model.SsPtType;
import com.hongxun.design.jungong.model.SspPhoto;
import com.hongxun.design.jungong.model.SspRecord;
import com.hongxun.design.listeners.MClickListener;
import com.hongxun.design.listeners.TouchListener_Iv;
import com.hongxun.design.mytools.IconSourse;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyDecimalFormat;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.SetTypeface;
import com.hongxun.design.mytools.ShardPreferencesTool;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.object_properties.MyMessage;
import com.hongxun.design.sqlite.bean.OfflineProMaterial;
import com.hongxun.design.ui.moveseekbar.SeekBarUtil;
import com.hongxun.design.ui.moveseekbar.SetSeek;
import com.hongxun.design.ui.moveseekbar.TextMoveLayout;
import com.hongxun.design.utils.DataUtil;
import com.hongxun.design.utils.FragmentUtil;
import com.hongxun.design.utils.PopwindowUtil;
import com.hongxun.design.utils.RegularUtil;
import com.hongxun.design.utils.fastjson.FastJsonUtil;
import com.hongxun.design.utils.fileutil.GetFileUtil;
import com.hongxun.design.utils.fileutil.SetFileUtil;
import com.hongxun.design.utils.fileutil.ZipUtil;
import com.hongxun.design.utils.httputil.HttpStringUtil;
import com.hongxun.design.utils.imageutil.UriUtil;
import com.hongxun.design.utils.projectdatautil.DataFactory;
import com.lidroid.xutils.http.RequestParams;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;

import zxing.encode.CodeCreator;

import static com.hongxun.design.MyApp.activity;
import static com.hongxun.design.activitys.RegeditActivity.isLetterDigit;

/**
 * Created by zerdoor_pc on 2016/5/5.
 */
public class MyDialog {
    /**
     * 加载效果dialog*
     */
    private static ProgressLoadingDialog dialog;

    static int times = 0;
    static Activity context;

    public static void Loading(Activity m) {
        if (context == null) return;
        context = m;
        context.runOnUiThread(new Runnable() {
            public void run() {

                times += 1;
                try {
                    if (dialog == null) {
                        try {
                            dialog = new ProgressLoadingDialog(context, MString.Loading, R.mipmap.load_image);
//                dialog = new ProgressLoadingDialog(context, MString.Loading, R.anim.dialog_loading_style);
//                dialog = new ProgressLoadingDialog(context, MString.Loading, R.mipmap.image_load);
//                dialog = new ProgressLoadingDialog(context, MString.Loading, R.mipmap.image_load);
                            dialog.show();
                        } catch (Exception e) {
                        }

                    } else {
                        if (!dialog.isShowing()) dialog.show();
                    }

                } catch (Exception e) {
                    MyLog.L(MString.EXCEPTION + ":" + e.toString());
                }
            }
        });


    }

    public static void Close() {

        times -= 1;
        if (times < 0) {
            times = 0;
        }
        //MyLog.L("HTTP_   times="+times);
        if (times <= 0 && dialog != null && dialog.isShowing()) {
            try {
                dialog.dismiss();
            } catch (Exception e) {
            }
            dialog = null;
        }
    }

    /**
     * 创建项目完成dialog*
     */
    public static AlertDialog dialogForCreatePro(final Activity context, final Handler handler, final int i) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_createpro, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        ImageView iv_back = (ImageView) view.findViewById(R.id.dialog_create_iv_back);

        title.setText("项目创建成功!");
        words.setText("继续操作，或者关闭则进入项目列表");
        button_back.setText("点位采集");
        button_go.setText("组装材料");

        final AlertDialog dialog = builder.create();

        iv_back.setOnClickListener(new View.OnClickListener() {//返回项目列表
            @Override
            public void onClick(View v) {
                if (MyApp.handler != null) {
                    MyApp.handler.sendMessage(MyMessage.getMessage(Constant.HomeActivityCheck, Constant.FRAGMENT_FLAG_PROJECT));
                }
                dialog.dismiss();
                context.finish();
            }
        });
        //组装材料
        button_go.setOnClickListener(new View.OnClickListener() {//组装材料
            @Override
            public void onClick(View view) {
                if (MyApp.handler != null) {
                    Intent intent = new Intent(context, ProItemInfoActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString(MString.CODE, "1");
                    intent.putExtra("ii", bundle);
                    context.startActivity(intent);
                }
                dialog.dismiss();
                context.finish();
            }
        });
        //点位采集
        button_back.setOnClickListener(new View.OnClickListener() {//完成
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(i);
            }
        });
//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }


    /**
     * 选择项目完成dialog*
     */
    public static AlertDialog dialogForSelectPro(final Activity context, final Handler handler, final int i, final int position, final ProjectItemBean bean, final String s) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_createpro, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        title.setText("是否发送此项目？");
        words.setText(bean.getProject_name());
        button_back.setText("取消");
        button_go.setText("确认");
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View view) {
                dialog.dismiss();

            }
        });
        button_go.setOnClickListener(new View.OnClickListener() {//完成
            @Override
            public void onClick(View view) {
                handler.sendMessage(MyMessage.getMessage(i, Integer.parseInt(bean.getStage_id().length() > 0 ? bean.getStage_id() : MString.code_zero), position, s));
                dialog.dismiss();
            }
        });

//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }


    /**
     * 选择项目删除dialog*
     */
    public static AlertDialog dialogFordelectPro(final FragmentActivity context, final ProjectItemBean bean, final int position) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_prodelect, null);

        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        title.setText("提示");
        words.setText("确定删除项目" + bean.getProject_name() + "?(包括云端项目信息，所有踏勘点位记录和删除数据)");
        button_back.setText("取消");
        button_go.setText("删除");
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View view) {
                dialog.dismiss();

            }
        });
        button_go.setOnClickListener(new View.OnClickListener() {//完成
            @Override
            public void onClick(View view) {
                //handler.sendMessage(MyMessage.getMessage(i, Integer.parseInt(bean.getStage_id().length()>0?bean.getStage_id():MString.code_zero), position,s));
                String schedule = bean.getCurrent_schedule();
                if (!(schedule == null || schedule.length() == 0) && Integer.parseInt(schedule) > 11) {
                    ToastShow.showShort(context, "此阶段不能删除！");
                    dialog.dismiss();
                    return;
                }
                String is_exp = bean.getIs_exp();
                if (is_exp.equals(MString.code_zero) || is_exp.equals(MString.code_null)) {
                    FragmentUtil.getIntence(context).projectFragment.Delect(position);
                } else {
                    ToastShow.showShort(context, "此项目已经完成踏勘,无法删除！");
                }
                dialog.dismiss();
            }
        });

//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * 选择项目删除dialog*
     */
    public static AlertDialog dialogFordelectProject(Activity context, ProjectItemBean bean, Handler handler) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_prodelect, null);

        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        title.setText("提示");
        words.setText("确定删除项目" + bean.getProject_name() + "的缓存数据?");
        button_back.setText("取消");
        button_go.setText("删除");
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View view) {
                dialog.dismiss();

            }
        });
        button_go.setOnClickListener(new MClickListener(0, bean, handler) {
            @Override
            public void onClick(View view, int position, Object msg) {

                ProjectItemBean bean = (ProjectItemBean) msg;
//                SetFileUtil.delectProjectFile(bean);
                SetFileUtil.delectProjectCacheFile(bean);
                ((Handler) msg2).sendEmptyMessage(1);
                dialog.dismiss();
            }
        });

//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * (异常)项目删除缓存dialog*
     */
    public static AlertDialog dialogFordelectCacheProject(Activity context, ProjectItemBean bean, String text) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_prodelect, null);

        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        title.setText("提示");
        words.setText(text);
        button_back.setText("取消");
        button_go.setText("确定");
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View view) {
                dialog.dismiss();

            }
        });
        button_go.setOnClickListener(new MClickListener(0, bean, null) {
            @Override
            public void onClick(View view, int position, Object msg) {

                ProjectItemBean bean = (ProjectItemBean) msg;
                SetFileUtil.delectProjectCacheFile(bean);
                ToastShow.showShort(activity, "删除成功！");
                dialog.dismiss();
            }
        });

//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * 选择是否同步dialog
     * 含项目左滑同步
     */
    public static AlertDialog dialogForupdatePro(final Activity context, final ProjectItemBean bean, Handler... handler) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_createpro, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words = (TextView) view.findViewById(R.id.dialog_create_words);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        title.setText("是否同步项目？");
        words.setText(bean.getProject_name());
        button_back.setText("取消");
        button_go.setText("确认");
        currPath = "";
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {//返回
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        button_go.setOnClickListener(new View.OnClickListener() {//完成
            @Override
            public void onClick(View view) {
                currPath = "";
                BaseActivity.showWaitDialog(-1);
                String path = MyApp.File.getCachaPath() + MString.Request + File.separator + MString.Project_ + SetFileUtil.CheckStageId_type();
                try {
                    MyLog.L(MString.SUCCESSED + " path=" + path);
                    path = ZipUtil.zipFolder(path);
                    MyLog.L(MString.SUCCESSED + " path=" + path);
                    currPath = path;
                    MyApp.HTTP.checkStage(uphandler, 200, SetFileUtil.CheckStageId_type());
                } catch (Exception e) {
                    MyLog.L(MString.SUCCESSED + "e=" + e);
                    ToastShow.showShort(activity, e.toString());
                    BaseActivity.hideWaitIngDialog();
                }
                dialog.dismiss();
            }
        });

//      dialog.setTitle("自定义输入");
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    private static String currPath = "";
    private static Handler uphandler = new Handler() {
        String stageid = "";
        String p = "", p1 = "";

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 200:
                    if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                        MyApp.HTTP.upload(uphandler, HttpStringUtil.SUCCESSED, new File(currPath), SetFileUtil.CheckStageId_type());
                    } else {
                        MyDialog.dialogFordelectCacheProject(activity, MyApp.currProject, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                    }
                    break;
                case HttpStringUtil.SUCCESSED:
                    if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                        String path = FastJsonUtil.JsonToZipPathBean((String) msg.obj);
                        String num1 = "^[\\s\\S]*?_(\\d+)\\.zip$";
                        Matcher matcher = RegularUtil.getMatcher(num1, path);
                        if (matcher.matches()) {
                            MatchResult mr = matcher.toMatchResult();
                            stageid = mr.group(1);
                            if (path.length() > 0) {
                                p = MyApp.File.getCachaPath() + MString.Request + File.separator + MString.Project_ + SetFileUtil.CheckStageId_type();
                                MyApp.File.delect(p);//删除文件夹
                                MyApp.File.delect(p + ".zip");//删除文件夹压缩包
                                ToastShow.showShort(activity, "项目上传成功,正在同步项目！");
                                MyApp.HTTP.download(path, MyApp.File.getCachaPath(), MString.Project_ + stageid, ".zip", uphandler);//下载文件
                                //DataFactory.setUpdateOn(false);//取消更新标识
                            }
                        } else {
                            MyLog.L(MString.SUCCESSED + "  mr.group(1)=error");
                            ToastShow.showShort(activity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                            BaseActivity.hideWaitIngDialog();
                        }
                    } else {
                        BaseActivity.hideWaitIngDialog();
                        ToastShow.showShort(activity, FastJsonUtil.JsonToCheck_String((String) msg.obj));
                    }
                    break;
                case 1://MyApp.HTTP.download：onSuccess
                    String toJson1 = upLoadPointMaterials();
                    if (toJson1 == null) {
                        uphandler.sendEmptyMessage(77);
                    } else {
                        MyApp.HTTP.upPointOfflineData(uphandler, 77, toJson1);
                        clearPointMaterials();
                    }
                    break;
                case 4://MyApp.HTTP.download：onFailure
                    String toJson4 = upLoadPointMaterials();
                    if (toJson4 == null) {
                        uphandler.sendEmptyMessage(78);
                    } else {
                        MyApp.HTTP.upPointOfflineData(uphandler, 78, toJson4);
                        clearPointMaterials();
                    }
                    break;
                case HttpStringUtil.ERROR:
                    ToastShow.showShort(activity, (String) msg.obj);
                    break;
                case 77://0下载文件成功
                    MyApp.currProject.setStage_id(stageid);
                    MyApp.currProject.saveBean();
                    SetFileUtil.updateProjectStageListFile();
                    DataFactory.setUpdateOn(false);
                    FragmentUtil.getIntence(activity).projectFragment.onRefresh();
                    FragmentUtil.getIntence(activity).homeFragment.Refresh();
                    ToastShow.showShort(activity, "数据同步成功！");
                    if (DataFactory.handler != null) DataFactory.handler.sendEmptyMessage(2);
                    break;
                case 78://0下载文件失败
                    MyApp.currProject.setStage_id(stageid);
                    MyApp.currProject.saveBean();
                    SetFileUtil.updateProjectStageListFile();
                    DataFactory.setUpdateOn(false);
                    String s = GetFileUtil.getProjectInfo(MyApp.currProject.getUUID());
                    if (s != null && s.length() > 0) {
                        ProjectItemBean p = FastJsonUtil.JsonToGetProject(s);
                        p.setStage_id(stageid);
                        SetFileUtil.setProjectInfo(JSON.toJSONString(p));
                    }
                    FragmentUtil.getIntence(activity).projectFragment.onRefresh();
                    FragmentUtil.getIntence(activity).homeFragment.Refresh();
                    break;
            }
        }
    };

    //todo：同步本地项目点位离线数据
    public static String upLoadPointMaterials() {
        List<OfflineProMaterial> offlineProMaterials = new ArrayList<>();
        String read = ShardPreferencesTool.read(MyApp.context, MyApp.currProject.getProject_id(), "", 3);
        List<Exploration> listEP = JSON.parseArray(read, Exploration.class);
        if (listEP == null) listEP = new ArrayList<>();
        for (Exploration exp : listEP) {
            OfflineProMaterial material = new OfflineProMaterial();
            material.setPointId(exp.getExploration_id());
            material.setProId(MyApp.currProject.getProject_id());
            material.setProStagId(MyApp.currProject.getStage_id());
            //点设
            String key1 = MString.nxPointDs + exp.getExploration_id();
            String pms1 = ShardPreferencesTool.read(MyApp.context, key1, "", 3);
            List<CodeSetBean> beanList = JSON.parseArray(pms1, CodeSetBean.class);
            if (beanList != null && !beanList.isEmpty())
                material.setCodeSetId(beanList.get(0).getCodeset_id());
            //材料
            String key2 = MString.nxPointMaterial + exp.getExploration_id();
            String pms2 = ShardPreferencesTool.read(MyApp.context, key2, "", 3);
            List<MaterialBean> list2 = JSON.parseArray(pms2, MaterialBean.class);
            if (list2 != null) material.setMaterials(list2);
            //模块
            String key3 = MString.nxPointModel + exp.getExploration_id();
            String pms3 = ShardPreferencesTool.read(MyApp.context, key3, "", 3);
            List<MaterialBean> list3 = JSON.parseArray(pms3, MaterialBean.class);
            if (list3 != null) material.setModulars(list3);
            offlineProMaterials.add(material);
        }
        if (offlineProMaterials.isEmpty()) return null;
        else return FastJsonUtil.beanToJson(offlineProMaterials);
    }

    //清除本地项目点位离线数据
    public static void clearPointMaterials() {
        String read = ShardPreferencesTool.read(MyApp.context, MyApp.currProject.getProject_id(), "", 3);
        List<Exploration> listEP = JSON.parseArray(read, Exploration.class);
        if (listEP == null) listEP = new ArrayList<>();
        for (Exploration exp : listEP) {
            //清空点位点设
            String key1 = MString.nxPointDs + exp.getExploration_id();
            ShardPreferencesTool.delete(MyApp.context, key1, 3);
            //清空点位材料
            String key2 = MString.nxPointMaterial + exp.getExploration_id();
            ShardPreferencesTool.delete(MyApp.context, key2, 3);
            //清空点位模块
            String key3 = MString.nxPointModel + exp.getExploration_id();
            ShardPreferencesTool.delete(MyApp.context, key3, 3);
        }
        //清空项目点位
        ShardPreferencesTool.delete(MyApp.context, MyApp.currProject.getProject_id(), 3);
    }

    /**
     * 二维码Dialog*
     */
    public static void openCodeImage(Activity context, String msg) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_simple, null);
        SimpleDraweeView sim = (SimpleDraweeView) view.findViewById(R.id.dialog_sim);
        try {
            Bitmap bitmap = CodeCreator.createQRCode(msg);
            sim.setImageBitmap(bitmap);
        } catch (WriterException e) {
            e.printStackTrace();
        }
        new AlertDialog.Builder(context)
                .setView(view)
                .setInverseBackgroundForced(true)
                .show();
    }

    /**
     * 二维码Dialog*
     */
    public static void openCodeResult(Activity context, ScanHotBean bean) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_text, null);
        TextView text = (TextView) view.findViewById(R.id.dialog_text);
        String s = "";
        if (bean.getDeviceType().equals(MString.android)) {
            s = "请打开设置,连接WIFI:\n" + bean.getHotName();
        } else {
            s = "请对方打开设置,连接WIFI:\n" + bean.getHotName();
        }
        text.setText(s);
        new AlertDialog.Builder(context)
                .setTitle("提示")
                .setView(view)
                .setInverseBackgroundForced(true)
                .setNeutralButton("我知道了", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                })
                .show();
    }

    /**
     * 输入dialog*
     */
    public static AlertDialog dialogForEdieText(final Activity context, Object msg, Object m) {
        RadioInterfaceAdapter.Hollder hollder = (RadioInterfaceAdapter.Hollder) msg;
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);

        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        if (((NextDoorBean) m).text.length() != 0) {
            words.setText(((NextDoorBean) m).text);
        }
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);

        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        button_go.setOnClickListener(new MClickListener(0, hollder, m) {
            @Override
            public void onClick(View view, int position, Object msg) {
                //    if (words.getText().toString().length()>0){
                RadioInterfaceAdapter.Hollder hollder = (RadioInterfaceAdapter.Hollder) msg;
                ((NextDoorBean) msg2).text = words.getText().toString();
                hollder._title.setText(((NextDoorBean) msg2).text);
                //  }
                dialog.dismiss();
            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * 授权输入dialog*
     */
    public static AlertDialog dialogForAuthorEdieText(final Activity context, Object msg, Object m, final Handler UIHandler) {
        BuyMenuListAdapter.Holldler hollder = (BuyMenuListAdapter.Holldler) msg;
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        title.setText("人数");
        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        words.setText(((BuyMenuBean) m).getAddNum() + "");
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        words.setHint("请输入人数");
        words.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        button_go.setOnClickListener(new MClickListener(0, hollder, m) {
            @Override
            public void onClick(View view, int position, Object msg) {
                //    if (words.getText().toString().length()>0){
                BuyMenuListAdapter.Holldler hollder = (BuyMenuListAdapter.Holldler) msg;
                String result = words.getText().toString();
                if (result.length() > 0) {
                    try {

                        long addnum = Long.parseLong(result);
                        if (addnum < 9999) {
                            ((BuyMenuBean) msg2).setAddNum(Long.parseLong(result));
                            hollder.buy_addnum.setText(addnum + "");
                        }
                        // hollder.buy_addnum.setText(result);
                    } catch (Exception e) {
                        ((BuyMenuBean) msg2).setAddNum(0);
                        hollder.buy_addnum.setText("0");
                    }

                } else {
                    ((BuyMenuBean) msg2).setAddNum(0);
                    hollder.buy_addnum.setText("0");
                }
                UIHandler.sendEmptyMessage(1);
                dialog.dismiss();
            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }


    /**
     * 输入dialog*
     */
    public static AlertDialog dialogForInputUser(final Activity context) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        title.setText("密码找回");
        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        words.setHint("请输入要找回的用户名/手机号");
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        button_go.setOnClickListener(new MClickListener(0, 0) {
            @Override
            public void onClick(View view, int position, Object msg) {
                if (words.getText().toString().length() > 0) {
                    getSecurityProblem(dialog, context, words.getText().toString());
                } else {
                    ToastShow.showShort(context, "请输入要找回的用户名/手机号!");
                }

            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    private static void getSecurityProblem(final AlertDialog dialog, final Activity context, final String name) {
        Handler getSecurityProblemHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            Bundle bundle = new Bundle();
                            bundle.putString(MString.TYPE, MString.SECRET);
                            bundle.putString(MString.name, (String) msg.obj);
                            bundle.putString(MString.username, name);
                            IntentToActivity.intent(context, RegeditActivity.class, bundle);

                        } else {
                            ToastShow.showShort(context, s);
                        }
                        dialog.dismiss();
                        Close();
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(context, (String) msg.obj);

                        break;
                }
            }
        };
        MyApp.HTTP.getSecurityProblem(getSecurityProblemHandler, HttpStringUtil.SUCCESSED, name);
    }

    /**
     * 信息修改dialog*
     */
    public static AlertDialog dialogForInputInfo(final Activity context, Object msg, final Handler handler, final int UPDATE) {
        CreateDistanceBean bean = (CreateDistanceBean) msg;
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        title.setText(bean.getTitle());
        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        words.setHint("请在此输入" + bean.getTitle());

        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        button_go.setOnClickListener(new MClickListener(0, msg) {
            @Override
            public void onClick(View view, int position, Object msg) {
                if (words.getText().toString().length() > 0) {
                    CreateDistanceBean bean = (CreateDistanceBean) msg;
                    bean.setValue(words.getText().toString());
                    handler.sendEmptyMessage(UPDATE);
                    dialog.dismiss();
                } else {
                    ToastShow.showShort(context, "请输入新密码!");
                }
            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * 密码修改dialog*
     */
    public static AlertDialog dialogForInputPsw(final Activity context, final Handler handler, String token, String username) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittext, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        title.setText("新密码");
        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        words.setHint("请在此输入新密码");
        words.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        button_go.setOnClickListener(new MClickListener(0, token, username) {
            @Override
            public void onClick(View view, int position, Object msg) {
                if (words.getText().toString().length() > 0) {
                    updatePsw(dialog, context, handler, msg.toString(), msg2.toString(), words.getText().toString());
                } else {
                    ToastShow.showShort(context, "请输入新密码!");
                }
            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    /**
     * 编号修改dialog*
     */
    public static AlertDialog dialogForNumber(final Activity context, Object b, Object h) {
        SetPointInfItemBean bean = (SetPointInfItemBean) b;

        String number = bean.getValue();
        String head = number.split("-")[0];
        String end = number.replace(head + "-", "");


//        String num1 = "^([A-Za-z]+)-([0-9]+)$";
//     //   String num2 = "^([A-Za-z]+)-([^-]+)-([0-9]+)$";
//        //  if (number.matches(num1)){
//        Matcher matcher = RegularUtil.getMatcher(num1, number);
//      //  Matcher matcher2 = RegularUtil.getMatcher(num2, number);
//
//       // String body = "";
//        String end = "";
//        if (matcher.matches()) {
//            MatchResult mr = matcher.toMatchResult();
//            head = mr.group(1);
//            end = mr.group(2);
//            MyLog.L(MString.SUCCESSED + "  mr.group(1)=" + mr.group(1));
//            MyLog.L(MString.SUCCESSED + "  mr.group(2)=" + mr.group(2));
//        }
////        else if (matcher2.matches()) {
////            MatchResult mr = matcher2.toMatchResult();
////            head = mr.group(1);
////            body = mr.group(2);
////            end = mr.group(3);
////            MyLog.L(MString.SUCCESSED + "  mr.group(1)=" + mr.group(1));
////            MyLog.L(MString.SUCCESSED + "  mr.group(2)=" + mr.group(2));
////            MyLog.L(MString.SUCCESSED + "  mr.group(2)=" + mr.group(3));
////        }
//        else {
//            MyLog.L(MString.SUCCESSED + "  mr.group(1)=error");
//        }


        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_edittextnumber, null);
        TextView title = (TextView) view.findViewById(R.id.dialog_create_title);
        TextView words_head = (TextView) view.findViewById(R.id.dialog_create_words_head);
        title.setText("修改编号");
        final EditText words = (EditText) view.findViewById(R.id.dialog_create_words);
        words.setHint("请在此输入");
        words_head.setText(head + "-");
//        String digists = "0123456789";
//      String digists = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//        words.setKeyListener(DigitsKeyListener.getInstance(digists));
        words.setText(end);
        TextView button_back = (TextView) view.findViewById(R.id.dialog_create_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_create_button_go);
        final AlertDialog dialog = builder.create();
        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        final String finalHead = head;
        //  final String finalBody = body;
        final String finalEnd = end;
        button_go.setOnClickListener(new MClickListener(0, b, h) {
            @Override
            public void onClick(View view, int position, Object msg) {
                SetPointInfItemBean bean = (SetPointInfItemBean) msg;
                SetPointInformationAdapter.EdHolder holder = (SetPointInformationAdapter.EdHolder) msg2;
                String endValue = finalHead + "-" + words.getText().toString();
                String num1 = "^.*\\d+$";
                String num2 = "(\\d+)$";
                Matcher matcher = RegularUtil.getMatcher(num1, endValue);
                if (matcher.matches()) {
                    bean.setValue(endValue);
                    bean.setValueCode(endValue);
                    holder.create_value.setText(endValue);
                    dialog.dismiss();

                } else {
                    ToastShow.showShort(context, "编号尾数必须为数字!");
                }


            }
        });
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();
        return dialog;
    }

    private static void updatePsw(final AlertDialog dialog, final Activity context, final Handler handler, final String token, final String username, final String psw) {
        Handler getSecurityProblemHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case HttpStringUtil.SUCCESSED:
                        String s = FastJsonUtil.JsonToCheck_String((String) msg.obj);
                        if (FastJsonUtil.JsonToCheck((String) msg.obj)) {
                            ConsumerInfo info = FastJsonUtil.JsonToGetT((String) msg.obj, new TypeReference<ConsumerInfo>() {
                            });
//                            String openIdent = JSON.parseObject((String) msg.obj).getString(MString.openIdent);
                            MyApp.userInfo.setBean(info);
                            ShardPreferencesTool.saveshare(context, MString.login_userpsw, psw);
                            RegeditActivity.userPsw = psw;
                            handler.sendEmptyMessage(1);
                        } else {
                            ToastShow.showShort(context, s);
                        }
                        dialog.dismiss();
                        break;
                    case HttpStringUtil.ERROR:
                        ToastShow.showShort(context, (String) msg.obj);
                        break;
                }
            }
        };
        if (!isLetterDigit(psw)) {
            ToastShow.showShort(context, "密码只能输入数字与字母！");
            return;
        } else if (psw.length() > 15 || psw.length() < 6) {
            ToastShow.showShort(context, "密码只能输入6-15位字母与数字！");
            return;
        }
        MyApp.HTTP.reUpPsd(getSecurityProblemHandler, HttpStringUtil.SUCCESSED, username, token, psw);
    }

    @SuppressLint("NewApi")
    public static void dialogForSetPointLat(final Activity context, SetPointInfItemBean bean) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_setpoint, null);
        AlertDialog dialog = builder.create();
        dialog.setView(view, 0, 0, 0, 0);
        findViewAndSet(view, context, bean, dialog);
        dialog.setCancelable(false);//设置点击外部区域不消失
        ((SetPointInformationActivity) context).mMapView.setAlpha(0.5f);
        dialog.show();
    }

    @SuppressLint("NewApi")
    public static void findViewAndSet(View view, final Activity context, final SetPointInfItemBean bean, final AlertDialog dialog) {
        TextView button_back = (TextView) view.findViewById(R.id.dialog_setpoint_button_back);
        TextView button_go = (TextView) view.findViewById(R.id.dialog_setpoint_button_go);

        TextView lat = (TextView) view.findViewById(R.id.dialog_setpoint_lat);//纬度（分秒）
        final TextView lat_right = (TextView) view.findViewById(R.id.dialog_setpoint_lat_right);//纬度

        TextView lon = (TextView) view.findViewById(R.id.dialog_setpoint_lon);//经度（分秒）
        final TextView lon_right = (TextView) view.findViewById(R.id.dialog_setpoint_lon_right);//经度

        final EditText Altitude_edit = (EditText) view.findViewById(R.id.dialog_setpoint_altitude_edit);//海拔

        lat_right.setText(MyDecimalFormat.getDouble(bean.getLat()));
        lon_right.setText(MyDecimalFormat.getDouble(bean.getLon()));
        if (bean.getAltitude() == null || bean.getAltitude().length() == 0) {
            Altitude_edit.setText("");
        } else {
            Altitude_edit.setText(Double.parseDouble(bean.getAltitude() + "") + "");
        }
        Altitude_edit.setEnabled(false);
        TextMoveLayout latseekbar_Move = (TextMoveLayout) view.findViewById(R.id.dialog_latseekbar_Move);
        SeekBar latseekbar = (SeekBar) view.findViewById(R.id.dialog_latseekbar);
        //纬度改变范围
        TextView dialog_latmin = (TextView) view.findViewById(R.id.dialog_latmin);
        TextView dialog_latmax = (TextView) view.findViewById(R.id.dialog_latmax);

        TextMoveLayout lonseekbar_Move = (TextMoveLayout) view.findViewById(R.id.dialog_lonseekbar_Move);
        SeekBar lonseekbar = (SeekBar) view.findViewById(R.id.dialog_lonseekbar);
        //经度改变范围
        TextView dialog_lonmin = (TextView) view.findViewById(R.id.dialog_lonmin);
        TextView dialog_lonmax = (TextView) view.findViewById(R.id.dialog_lonmax);

        SeekBarUtil seekBarUtil_lat = new SeekBarUtil(view, context, latseekbar_Move, latseekbar, lat, lat_right);//纬度
        SeekBarUtil seekBarUtil_lon = new SeekBarUtil(view, context, lonseekbar_Move, lonseekbar, lon, lon_right);//经度


        button_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((SetPointInformationActivity) context).mMapView.setAlpha(1.0f);
                dialog.dismiss();

            }
        });
        button_go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bean.setAltitude(Altitude_edit.getText().toString());
                bean.setLat(Double.parseDouble(lat_right.getText().toString()));
                bean.setLon(Double.parseDouble(lon_right.getText().toString()));
                dialog.dismiss();
                ((SetPointInformationActivity) context).mMapView.setAlpha(1.0f);
                SetPointInformationActivity.adapter.notifyDataSetChanged();

            }
        });

        ////设置超链接
        //        sp.setSpan(new URLSpan("http://www.baidu.com"), 5, 7,
        //                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置高亮样式一
//        sp.setSpan(new BackgroundColorSpan(Color.RED), 17 ,19,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置高亮样式二          sp.setSpan(new ForegroundColorSpan(Color.YELLOW),20,24,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //设置斜体
//        sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 27, 29, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        //SpannableString对象设置给TextView

    }

    public static void dialogForSetPointLat2(final Activity context, SetPointInfItemBean bean) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.seek_ui, null);
        SetSeek setSeek = new SetSeek();
        setSeek.start(view, context);
        final AlertDialog dialog = builder.create();
        dialog.setView(view, 0, 0, 0, 0);
//      dialog.setTitle("自定义输入");
        dialog.setCancelable(false);//设置点击外部区域不消失
        dialog.show();

    }


    public static void dialogForPhotoPassage(Context context, PhotoPassagewayItemBean itemBean, final Handler handler) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_photopass, null);
        final Dialog dialog = new Dialog(context);

//        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.getWindow().setBackgroundDrawable(new BitmapDrawable());// 这样设置才能点击屏幕外dismiss窗口
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(view);
        dialog.show();

        WindowManager windowManager = ((Activity) context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = display.getWidth(); //设置宽度
        dialog.getWindow().setAttributes(lp);

        //  AlertDialog.Builder builder = new AlertDialog.Builder(context);
        TextView title = (TextView) view.findViewById(R.id.dialog_photo_title);//标题
        TextView preser = (TextView) view.findViewById(R.id.dialog_photo_preser);//保存
        TextView delect = (TextView) view.findViewById(R.id.dialog_photo_delect);//删除
        ListView listView = (ListView) view.findViewById(R.id.dialog_photo_list);//数据
        RelativeLayout outview = (RelativeLayout) view.findViewById(R.id.outview);
        title.setText(itemBean.getName());
        PPassDialogAdapter adapter = new PPassDialogAdapter(itemBean.getDialogBean(), (Activity) context, outview);
        listView.setAdapter(adapter);
        preser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(Constant.DIALOGBACK);
                dialog.dismiss();
            }
        });
        delect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(Constant.DELECT);
                dialog.dismiss();
            }
        });

    }


    public static Handler dialogUpExpMaterialHandler;
    static long obj_id;

    public static void dialogForUpExpMaterial(final int type, final Context context, final Object itemBean,
                                              final Handler handler) {
        obj_id = 0;
        dialogUpExpMaterialHandler = null;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_upexpmaterial, null);
        final Dialog dialog = new Dialog(context);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.setContentView(view);
        dialog.show();

        TextView title = (TextView) view.findViewById(R.id.dialog_upexpmaterial_title);//标题
        TextView preser = (TextView) view.findViewById(R.id.dialog_upexpmaterial_preser);//保存
        TextView cancel = (TextView) view.findViewById(R.id.dialog_upexpmaterial_cancel);//取消
        TextView right = (TextView) view.findViewById(R.id.dialog_upexpmaterial_right);//取消
        RelativeLayout title_main = (RelativeLayout) view.findViewById(R.id.dialog_upexpmaterial_main);

        title.setText("编辑材料");
        TextView name = (TextView) view.findViewById(R.id.dialog_upexpmaterial_name);//材料名
        final TextView spec = (TextView) view.findViewById(R.id.dialog_upexpmaterial_spec);//材料型号
        final String id = ((MaterialBean) itemBean).getCodeset_material_id();
        name.setText(((MaterialBean) itemBean).getName());
        spec.setText(((MaterialBean) itemBean).getSpec());

        //利旧隐藏
        view.findViewById(R.id.dialog_upexpmaterial_old_button).setVisibility(View.GONE);

        TextView reduce = (TextView) view.findViewById(R.id.dialog_upexpmaterial_reduce);//数量-
        final EditText num = (EditText) view.findViewById(R.id.dialog_upexpmaterial_num);//数量
        final String value = ((MaterialBean) itemBean).getNum();
        num.setText(value);
        TextView add = (TextView) view.findViewById(R.id.dialog_upexpmaterial_add);//数量+
        SetTypeface.set(add, IconSourse.ADD);

        num.setSelection(value.length());
        num.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String trim = num.getText().toString().trim();
                num.setSelection(0, trim.length());
            }
        });

        //数量减
        reduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = num.getText().toString().trim();
                double aDouble = -1;
                try {
                    aDouble = Double.parseDouble(trim);
                    aDouble--;
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                if (aDouble == 0 || aDouble > 0) {
                    num.setText(aDouble + "");
                } else {
                    num.setText("0");
                    ToastShow.showShort(context, "数量已为0");
                    return;
                }
            }
        });
        //数量加
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = num.getText().toString().trim();
                double aDouble = -1;
                try {
                    aDouble = Double.parseDouble(trim);
                    aDouble++;
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                num.setText(aDouble + "");

            }
        });
        if (!((MaterialBean) itemBean).getObj_type().equals("1")) {
            SetTypeface.set(right, IconSourse.RIGHTARROW);
            title_main.setOnClickListener(new MClickListener(0, itemBean) {
                @Override
                public void onClick(View view, int position, Object msg) {
                    Bundle bundle = new Bundle();
                    bundle.putString(MString.TYPE, MString.Type_Material);
                    bundle.putString(MString.CODE, id);
                    IntentToActivity.intent((Activity) context, CreateProjectAttributeCodeActivity.class, bundle);
                }
            });
        }

        dialogUpExpMaterialHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        String newSpec = (String) msg.obj;
                        spec.setText(newSpec);
                        break;
                    case 2:
                        obj_id = Long.valueOf((String) msg.obj);
                        break;
                }
            }
        };
        preser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                String use_type = MString.NEW;
                String trim = num.getText().toString().trim();
                double aDouble = 0;
                try {
                    aDouble = Double.parseDouble(trim);
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                //先修改显示数据
                handler.sendMessage(MyMessage.getMessage(1, aDouble + ""));
                //再修改数据库数据
                if (type == Constant.EdModel) {
                    RequestParams params = new RequestParams();
                    params.addBodyParameter("id", id + "");
                    params.addBodyParameter("num", aDouble + "");
                    MyApp.HTTP.UpModelMaterial1(handler, params, HttpStringUtil.SUCCESSED);
                } else {
                    RequestParams params = new RequestParams();
                    params.addBodyParameter("matId", id);
                    params.addBodyParameter("obj_id", obj_id + "");
                    params.addBodyParameter("num", aDouble + "");
                    MyApp.HTTP.UpModelMaterial(handler, params, HttpStringUtil.SUCCESSED);
                }
                dialog.dismiss();
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

    }


    public static void dialogForUpExpMaterial1(final Context context, final Object itemBean, final Handler handler) {
        obj_id = 0;
        dialogUpExpMaterialHandler = null;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_upexpmaterial, null);
        final Dialog dialog = new Dialog(context);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.setContentView(view);
        dialog.show();

        TextView title = (TextView) view.findViewById(R.id.dialog_upexpmaterial_title);//标题
        TextView preser = (TextView) view.findViewById(R.id.dialog_upexpmaterial_preser);//保存
        TextView cancel = (TextView) view.findViewById(R.id.dialog_upexpmaterial_cancel);//取消
        TextView right = (TextView) view.findViewById(R.id.dialog_upexpmaterial_right);//取消
        RelativeLayout title_main = (RelativeLayout) view.findViewById(R.id.dialog_upexpmaterial_main);
        final String id = ((MaterialBean) itemBean).getId();

        if (((MaterialBean) itemBean).getObj_type().equals("1")) {
            right.setVisibility(View.GONE);
        } else {
            right.setVisibility(View.VISIBLE);
            //无网络时不能切换材料类别(删除后再添加)
            if (!MyApp.NetWorkConnect) right.setVisibility(View.GONE);
            else {
                right.setVisibility(View.VISIBLE);
                SetTypeface.set(right, IconSourse.RIGHTARROW);
                //换型号
                title_main.setOnClickListener(new MClickListener(0, itemBean) {
                    @Override
                    public void onClick(View view, int position, Object msg) {
                        Bundle bundle = new Bundle();
                        bundle.putString(MString.TYPE, MString.Type_Material);
                        bundle.putString(MString.CODE, id);
                        bundle.putBoolean("true", true);
                        IntentToActivity.intent((Activity) context, CreateProjectAttributeCodeActivity.class, bundle);
                    }
                });
            }
        }
        title.setText("编辑材料");
        TextView name = (TextView) view.findViewById(R.id.dialog_upexpmaterial_name);//材料名
        final TextView spec = (TextView) view.findViewById(R.id.dialog_upexpmaterial_spec);//材料型号
        name.setText(((MaterialBean) itemBean).getName());
        spec.setText(((MaterialBean) itemBean).getSpec());
        //修改点位材料时显示利旧
        LinearLayout old_button = (LinearLayout) view.findViewById(R.id.dialog_upexpmaterial_old_button);//利旧按钮
        old_button.setVerticalGravity(View.VISIBLE);

        final TextView old = (TextView) view.findViewById(R.id.dialog_upexpmaterial_old);//利旧状态
        MaterialBean bean = (MaterialBean) itemBean;
        if (bean.getUse_type() != null && bean.getUse_type().equals(MString.NEW)) {
            old.setText(MString.YES);
            old.setBackgroundResource(R.drawable.circular_red_2);
        } else {
            old.setText(MString.NO);
            old.setBackgroundResource(R.drawable.circular_gray_2);
        }

        TextView reduce = (TextView) view.findViewById(R.id.dialog_upexpmaterial_reduce);//数量-
        final EditText num = (EditText) view.findViewById(R.id.dialog_upexpmaterial_num);//数量
        final String value = ((MaterialBean) itemBean).getNum();
        num.setText(value);
        TextView add = (TextView) view.findViewById(R.id.dialog_upexpmaterial_add);//数量+
        SetTypeface.set(add, IconSourse.ADD);

        num.setSelection(value.length());
        num.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String trim = num.getText().toString().trim();
                num.setSelection(0, trim.length());
            }
        });

//        利旧状态改变
        old_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (old.getText().equals(MString.YES)) {
                    old.setText(MString.NO);
                    old.setBackgroundResource(R.drawable.circular_gray_2);
                } else {
                    old.setText(MString.YES);
                    old.setBackgroundResource(R.drawable.circular_red_2);
                }
            }
        });
        //数量减
        reduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = num.getText().toString().trim();
                double aDouble = -1;
                try {
                    aDouble = Double.parseDouble(trim);
                    aDouble--;
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                if (aDouble == 0 || aDouble > 0) {
                    num.setText(aDouble + "");
                } else {
                    num.setText("0");
                    ToastShow.showShort(context, "数量已为0");
                    return;
                }
            }
        });
        //数量加
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = num.getText().toString().trim();
                double aDouble = -1;
                try {
                    aDouble = Double.parseDouble(trim);
                    aDouble++;
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                num.setText(aDouble + "");
            }
        });

        dialogUpExpMaterialHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 1:
                        String newSpec = (String) msg.obj;
                        spec.setText(newSpec);
                        break;
                    case 2:
                        obj_id = Long.valueOf((String) msg.obj);
                        break;
                }
            }
        };
        preser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = num.getText().toString().trim();
                double aDouble = 0;
                try {
                    aDouble = Double.parseDouble(trim);
                } catch (NumberFormatException e) {
                    ToastShow.showShort(context, "数量格式错误");
                    return;
                }
                dialog.dismiss();
                BaseActivity.showWaitDialog(-1, "处理中...");
                String use_type = "";
                if (old.getText().toString().equals(MString.NO)) {
                    use_type = MString.OLD;
                } else {
                    use_type = MString.NEW;
                }
                Bundle bundle = new Bundle();
                bundle.putDouble("1", aDouble);
                bundle.putString("2", use_type);
                bundle.putString("3", spec.getText().toString().trim());
//                bundle.putLong("4", obj_id);
                Message msg = handler.obtainMessage();
                msg.obj = itemBean;
                msg.setData(bundle);
                msg.what = 10;
                handler.sendMessage(msg);
//                handler.sendMessage(MyMessage.getMessage(1, Integer.parseInt(trim), 0, use_type));
                if (MyApp.NetWorkConnect)
                    MyApp.HTTP.UpExpMaterial(handler, HttpStringUtil.SUCCESSED, id, obj_id + "", aDouble + "", use_type);
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

    }

    public static void payDialog(Context context, String buy_menu_id, String people_num, String type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_paychoice, null);
        //TextView  title= (TextView) view.findViewById(R.id.dialog_pay_title);
        ListView list = (ListView) view.findViewById(R.id.dialog_pay_list);
//        MyLog.L(MString.SUCCESSED + "22=   buy_menu_id=" + buy_menu_id + "&people_num=" + people_num + "&type=" + type);
        final AlertDialog dialog = builder.create();
        DialogPayAdapter adapter = new DialogPayAdapter(context, DataUtil.getPayData(), buy_menu_id,
                people_num, type, dialog);
        list.setAdapter(adapter);
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCancelable(true);//设置点击外部区域不消失
        dialog.show();
    }

    /**
     * 新增/修改记录
     * 0activity
     * 1title
     * 2hander
     * 3bean
     * 4position
     * 5List<SsPtType>
     */
    public static void RecordOperation(Object... bean) {
        final Activity activity = (Activity) bean[0];
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_record, null);
        final Dialog dialog = new Dialog(activity);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(view);
        dialog.show();

        LinearLayout layout = (LinearLayout) view.findViewById(R.id.record_llitem1);
        TextView tvtitle = (TextView) view.findViewById(R.id.record_title);
        TextView tvdel = (TextView) view.findViewById(R.id.record_title_del);
        final TextView tv1 = (TextView) view.findViewById(R.id.recordtv1);
        TextView tv1Icon = (TextView) view.findViewById(R.id.recordtv1_icon);
        final EditText et1 = (EditText) view.findViewById(R.id.recordet1);
        final EditText et2 = (EditText) view.findViewById(R.id.recordet2);
        TextView tv2Icon = (TextView) view.findViewById(R.id.recordet2_icon);
        TextView tvL = (TextView) view.findViewById(R.id.record_tvL);
        TextView tvR = (TextView) view.findViewById(R.id.record_tvR);

        SetTypeface.set(tv1Icon, IconSourse.DROPDOWN);
        SetTypeface.set(tv2Icon, IconSourse.SEARCH);

        tvtitle.setText(String.valueOf(bean[1]));
        if (bean[3] instanceof SspRecord) {
            SspRecord record = (SspRecord) bean[3];
            tv1.setText(record.getPname());
            et1.setText(record.getKwords());
            et2.setText(record.getPileseat());
        }
        tvdel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        final List<SsPtType> typeList = (List<SsPtType>) bean[5];
        final ArrayList<String> list = new ArrayList<>();
        for (SsPtType type : typeList) {
            list.add(type.getTname());
        }

        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                tv1.setText(list.get(msg.arg1));
            }
        };
        //记录类型下拉选择
        if (!String.valueOf(bean[1]).contains("修改"))
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PopwindowUtil.dropdownpop(activity, list, v, handler, 0);
                }
            });
        //桩号搜索
        tv2Icon.setVisibility(View.GONE);
        //保存
        final Handler handler1 = (Handler) bean[2];
        final int position = (int) bean[4];

        tvL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String pname = String.valueOf(tv1.getText().toString().trim());
                String keyword = String.valueOf(et1.getText().toString().trim());
                String pileseat = String.valueOf(et2.getText().toString().trim());
                if (pname.isEmpty()) {
                    ToastShow.showShort(activity, "请选择记录类型");
                    return;
                }
                if (keyword.isEmpty()) {
                    ToastShow.showShort(activity, "请录入关键信息");
                    return;
                }
                dialog.dismiss();

                int index = list.indexOf(pname);
                Message message = new Message();
                message.what = 5;
                Bundle bundle = new Bundle();
                bundle.putSerializable("0", typeList.get(index));
                bundle.putString("1", pname);
                bundle.putString("2", keyword);
                bundle.putString("3", pileseat);
                message.setData(bundle);
                message.arg1 = position;
                handler1.sendMessage(message);
            }
        });
        //拍照
        tvR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String pname = String.valueOf(tv1.getText().toString().trim());
                String keyword = String.valueOf(et1.getText().toString().trim());
                String pileseat = String.valueOf(et2.getText().toString().trim());
                if (pname.isEmpty()) {
                    ToastShow.showShort(activity, "请选择记录类型");
                    return;
                }
                if (keyword.isEmpty()) {
                    ToastShow.showShort(activity, "请录入关键信息");
                    return;
                }
                dialog.dismiss();

                int index = list.indexOf(pname);
                Message message = new Message();
                message.what = 6;
                message.obj = pname + "," + keyword + "," + pileseat;
                Bundle bundle = new Bundle();
                bundle.putSerializable("0", typeList.get(index));
                bundle.putString("1", pname);
                bundle.putString("2", keyword);
                bundle.putString("3", pileseat);
                message.setData(bundle);
                message.arg1 = position;
                handler1.sendMessage(message);
            }
        });

    }

    /**
     * 删除记录
     * 0activity
     * 1List<String>
     * 2hander
     * 3bean
     * 4case index_yes
     * 5case index_no
     */
    public static void recordDel(Object... bean) {
        final Activity activity = (Activity) bean[0];
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_record_del, null);
        final Dialog dialog = new Dialog(activity);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(view);
        dialog.show();

        TextView tvtitle = (TextView) view.findViewById(R.id.record_title);
        TextView tvmsg = (TextView) view.findViewById(R.id.record_tvmsg);
        TextView tvL = (TextView) view.findViewById(R.id.record_tvL);
        TextView tvR = (TextView) view.findViewById(R.id.record_tvR);

        List<String> list = (List<String>) bean[1];
        tvtitle.setText(list.get(0));
        tvmsg.setText(list.get(1));
        tvL.setText(list.get(2));
        tvR.setText(list.get(3));

        final Handler handler = (Handler) bean[2];
        final Object obbj = bean[3];
        final int indexNo = (int) bean[4];
        final int indexYes = (int) bean[5];
        tvL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (indexNo != 0) {
                    Message message = handler.obtainMessage();
                    message.obj = obbj;
                    message.what = indexNo;
                    handler.sendMessage(message);
                }
            }
        });
        tvR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Message message = handler.obtainMessage();
                message.obj = obbj;
                message.what = indexYes;
                handler.sendMessage(message);
            }
        });
    }

    private static int positionImg = 0;
    private static List<SspPhoto> photoListY;
    private static List<SspPhoto> photoListN;

    /**
     * 查看照片大图并可缩放
     * 0activity
     * 1SspRecord record
     * 2Message msg
     */
    public static void showBigImgDialog(Object... bean) {
        photoListY = new ArrayList<>();
        photoListN = new ArrayList<>();
        final Activity activity = (Activity) bean[0];
        Display display = activity.getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width * 4 / 5, height * 4 / 5);
        View view = LayoutInflater.from(activity).inflate(R.layout.dialog_showbigimg, null);
        final Dialog dialog = new Dialog(activity);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(view, params);
        dialog.show();

        final TextView tv1 = (TextView) view.findViewById(R.id.sbg_tv1);
        TextView tv2 = (TextView) view.findViewById(R.id.sbg_tv2);
        TextView tv3 = (TextView) view.findViewById(R.id.sbg_tv3);
        TextView tv4 = (TextView) view.findViewById(R.id.sbg_tv4);
        TextView tv5 = (TextView) view.findViewById(R.id.sbg_tv5);

        final ImageView imageView = (ImageView) view.findViewById(R.id.big_image);

//        final MatrixImageView imageView = (MatrixImageView) view.findViewById(R.id.big_image);

        SetTypeface.set(tv4, IconSourse.BACK);
        SetTypeface.set(tv5, IconSourse.RIGHTARROW);

        final SspRecord record = (SspRecord) bean[1];
        tv2.setText(record.getPileseat() + "\t" + record.getKwords());
        tv3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

        Message msg = (Message) bean[2];
        imageView.setImageURI(UriUtil.getUri(String.valueOf(msg.obj)));
        imageView.setOnTouchListener(new TouchListener_Iv(imageView, activity));

        if (msg.arg2 == -2) {
            tv1.setVisibility(View.GONE);
            tv4.setVisibility(View.GONE);
            tv5.setVisibility(View.GONE);
        } else {
            String photots = ShardPreferencesTool.getrecord(activity, record.getGuid(), "");
            List<SspPhoto> photoList = JSON.parseArray(photots, SspPhoto.class);
            for (SspPhoto photo : photoList) {
                if (photo.getIsdel().equalsIgnoreCase("删除")) photoListN.add(photo);
                else photoListY.add(photo);
            }
            positionImg = msg.arg2;//01234
            tv1.setText(positionImg + 1 + "/" + photoListY.size());
            tv4.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (0 == photoListY.size()) {
                        ToastShow.showShort(activity, "暂无图片");
                        return;
                    }
                    positionImg--;
                    if (positionImg >= 0) {
                        imageView.setImageURI(UriUtil.getUri(photoListY.get(positionImg).getImgaddress()));
                        tv1.setText(positionImg + 1 + "/" + photoListY.size());
                    } else {
                        positionImg++;
                    }
                }
            });
            tv5.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (0 == photoListY.size()) {
                        ToastShow.showShort(activity, "暂无图片");
                        return;
                    }
                    positionImg++;
                    if (positionImg < photoListY.size()) {
                        imageView.setImageURI(UriUtil.getUri(photoListY.get(positionImg).getImgaddress()));
                        tv1.setText(positionImg + 1 + "/" + photoListY.size());
                    } else {
                        positionImg--;
                    }
                }
            });
        }
    }

    private static Overlay overlay;

    /**
     * 依据档距拖动定位
     * 0Activity activity
     * 1LatLng point
     * 2BaiduMap mBaiduMap
     */
    public static void setPointDistance(Object... obj) {
        final Activity activity = (Activity) obj[0];
        final LatLng point = (LatLng) obj[1];
        final BaiduMap mBaiduMap = (BaiduMap) obj[2];
        final Dialog dialog_dis = new Dialog(activity);
        final List<Exploration> pointData = (List<Exploration>) obj[3];

        View view = LayoutInflater.from(activity).inflate(R.layout.view_ra_distance, null);
        dialog_dis.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        dialog_dis.setCanceledOnTouchOutside(false);
        dialog_dis.setContentView(view);
        if (!dialog_dis.isShowing()) dialog_dis.show();

        final EditText idet_dist = (EditText) view.findViewById(R.id.et_dist);
        view.findViewById(R.id.tv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog_dis.dismiss();
            }
        });
        view.findViewById(R.id.tv_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (overlay != null) overlay.remove();
                String dis = String.valueOf(idet_dist.getText().toString().trim());
                if (TextUtils.isEmpty(dis)
                        || dis.equals(".")
                        || dis.indexOf(".") == dis.length() - 1) {
                    ToastShow.showShort(activity, "请录入正确的数字");
                    return;
                }
                dialog_dis.dismiss();
                for (Exploration e : pointData) {
                    if (Double.parseDouble(e.lat) == point.latitude && Double.parseDouble(e.lng) == point.longitude) {
                        MyApp.isDistance = true;
                        MyApp.distanceCode = e.getExploration_id();
                        MyApp.distanceName = e.getNumber();
                        break;
                    }
                }
                MyApp.currExploration.setDistance(dis);
                Double disd = Double.parseDouble(dis);
                int radius = disd.intValue();
                //档距传递
                /*​设置颜色和透明度，均使用16进制显示，0xAARRGGBB，如 0xAA000000 其中AA是透明度，000000为颜色*/
                OverlayOptions ooCircle = new CircleOptions().fillColor(0x000000FF)
                        .center(point).stroke(new Stroke(5, 0xAA000000)).radius(radius);
                overlay = mBaiduMap.addOverlay(ooCircle);
                //设置缩放
                float zoomLevel = mBaiduMap.getMapStatus().zoom;
                float maxZoomLevel = mBaiduMap.getMaxZoomLevel();
                for (int i = 0; i < maxZoomLevel - zoomLevel; i++) {
                    mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomIn());
                }
            }
        });
    }
}
